﻿//==============================================================================  
//Copyright (C) 2012-2015 9UN.ORG. All rights reserved. 
//GUID：46172595-6b69-4526-b9da-426d663f5b05
//CLR Version: 4.0.30319.18033
//Code Author：Kevin Wang
//Contact：Email(Admin@9un.org),QQ(265382 or 74344)
//Filename：MediaLibraryFactory
//Namespace：RuanRang.Media.Core
//Functions：MediaLibraryFactory  
//Created by Kevin Wang at 2013/2/2 23:05:09 http://blog.9un.org
//============================================================================== 

#region Usings

using System;
using System.IO;

#endregion

namespace RuanRang.Media.Core.Io
{
    /// <summary>
    /// Represents input media stream.
    /// </summary>
    public class MediaInput
    {
        private readonly string _source;
        private readonly MediaInputType _type;

        /// <summary>
        /// Instantiates media input using wpecified type and source.
        /// </summary>
        /// <param name="type">Type of media stream.</param>
        /// <param name="source">String which identifies source of media resource.</param>
        /// <exception cref="ArgumentOutOfRangeException">Invalid type of media input.</exception>
        /// <exception cref="ArgumentNullException">Source string is null.</exception>
        /// <exception cref="ArgumentException">Source string is empty.</exception>
        /// <exception cref="FileNotFoundException">If media type is <code>MediaInputType.File</code> and source file does not exists.</exception>
        public MediaInput(MediaInputType type, string source)
        {
            if (type < MediaInputType.File || type > MediaInputType.UnparsedMrl)
            {
                throw new ArgumentOutOfRangeException("type");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (source.Length == 0)
            {
                throw new ArgumentException("Source string cannot be empty.", "source");
            }
            //
            if (type == MediaInputType.File)
            {
                if (!File.Exists(source))
                {
                    throw new FileNotFoundException("Source file not found.", source);
                }
            }
            //
            _type = type;
            _source = source;
        }

        /// <summary>
        /// Type of media stream.
        /// </summary>
        public MediaInputType Type
        {
            get
            {
                return (_type);
            }
        }

        /// <summary>
        /// String which identifies source of media resource.
        /// </summary>
        public string Source
        {
            get
            {
                return (_source);
            }
        }
    }
}